import math
import os

from numpy import number
def getEuclideanDistance(vector1, vector2):
  if len(vector1) != len(vector2):
    raise ValueError('传入的两个向量长度相等')
  res = 0
  for i in range(len(vector1)):
    res += (vector1[i] - vector2[i]) * (vector1[i] - vector2[i])
  res = math.sqrt(res)
  return res

def getFilenameByNumber(num):
  if num > 9999:
    raise ValueError('输入的数字超过5位数')
  return "image_" + ("%04d" % num) + ".jpg"

def getFilePathListByDirname(dirname, limit = -1):
  path = os.path.join(os.getcwd(), '101_ObjectCategories', dirname)
  if not os.path.isdir(path):
    raise ValueError(path + '不是一个文件夹')
  res = []
  if limit == -1:
    for item in os.listdir(path):
      if os.path.isfile(os.path.join(path, item)):
        res.append(os.path.join(path, item))
  else:
    for i in range(1, limit + 1):
      if os.path.isfile(os.path.join(path, getFilenameByNumber(i))):
        res.append(os.path.join(path, os.path.join(path, getFilenameByNumber(i))))
  return res

def getIndexByFilename(filename):
  return number(filename[6:9])
